package com.googlecode.intellimars.mrsp;

import jp.sourceforge.mrsp.model.Artifact;

public class MavenTagMaker {
    public static final String create(Artifact artifact, String scope, boolean isRepo) {
        return isRepo ? createRepositoryTag(artifact)
               : createDependencyTag(artifact, scope);
    }

    private static final String createRepositoryTag(Artifact artifact) {
        StringBuilder builder = new StringBuilder();
        builder.append("<repository>").append(CR);
        builder.append("  <id>").append(artifact.getGroupId()).append("</id>").append(CR);
        builder.append("  <name>").append(artifact.getGroupId()).append("</name>").append(CR);
        builder.append("  <url>").append(artifact.getRepoUrl()).append("</url>").append(CR);
        builder.append("  <!--<layout>legacy</layout>-->").append(CR);
        builder.append("</repository>").append(CR);
        return builder.toString();
    }


    private static final String createDependencyTag(Artifact artifact, String scope) {
        StringBuilder builder = new StringBuilder();
        builder.append("<dependency>").append(CR);
        builder.append("  <groupId>").append(artifact.getGroupId()).append("</groupId>").append(CR);
        builder.append("  <artifactId>").append(artifact.getArtifactId()).append("</artifactId>").append(CR);
        builder.append("  <version>").append(artifact.getVersion()).append("</version>").append(CR);
        if (!artifact.getType().equals("jar"))
            builder.append("  <type>").append(artifact.getType()).append("</type>").append(CR);
        if (!scope.equals(""))
            builder.append("  <scope>").append(scope).append("</scope>").append(CR);
        builder.append("</dependency>").append(CR);
        return builder.toString();
    }

    private static final String CR = System.getProperty("line.separator");
}
